package com.aaa.controller;

import com.aaa.pojo.ChangeMoney;
import com.aaa.pojo.Credit;
import com.aaa.pojo.PersonUser;
import com.aaa.pojo.UserInfo;
import com.aaa.service.PersonUserService;
import com.aaa.service.UserService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private PersonUserService personUserService;
    @Autowired
    private UserService userService;

    @RequestMapping(name = "用户个人信息",value = "/getPersonUserList/{currentPage}/{pageSize}",method = RequestMethod.GET)
    @ResponseBody
    public PageInfo<PersonUser> getPersonUser(@PathVariable(name = "currentPage") int currentPage, @PathVariable(name = "pageSize") int pageSize){
        return personUserService.getPersonUserByPage(currentPage,pageSize);
    }
    @RequestMapping(name="查询个人用户信息",value = "/selectPersonUser")
    @ResponseBody
    public Map<String,Object> PersonUser(Integer pid){
       Map<String,Object> map=new HashMap<>();
       PersonUser personUser=personUserService.selectPerUserByPid(pid);
        map.put("personUser",personUser);
        System.out.println(personUser.getUserInfo());
        map.put("userInfo",personUser.getUserInfo());
        return map;
    }
    @PostMapping(name="修改个人信息",value = "/updatePersonUser")
    @ResponseBody
    public String updatePersonUser(Integer pid, String username, String pname,Long phone,String email){
        if(personUserService.updatePersonal(pid, username, pname, phone, email)){
            return "";
        }
            return "";
    }
    @PostMapping(name="删除个人信息",value = "/deletePersonUser")
    @ResponseBody
    public Map<String,Object> deletePersonUser(Integer pid,Integer uid){
        Map<String,Object> map=new HashMap<>();
        if(personUserService.deletePersonal(pid)){
            if(personUserService.updateUser(uid)){
                List<PersonUser> list=personUserService.selectPersonal();
                map.put("personUser",list);
                return map;
            }
        }
        List<PersonUser> list=personUserService.selectPersonal();
        map.put("personUser",list);
        return map;
    }

    @RequestMapping(name = "用户信誉管理",value = "/getCreditList/{currentPage}/{pageSize}",method = RequestMethod.GET)
    @ResponseBody
    public PageInfo<Credit> getUserCredictCredit(@PathVariable(name = "currentPage") int currentPage, @PathVariable(name = "pageSize") int pageSize){
        return userService.getUserCreditByPage(currentPage,pageSize);
    }
    @RequestMapping(name="查询个人征信信息",value = "/selectCreditbyId")
    @ResponseBody
    public Map<String,Object> UserCreidt(Integer uid){
        Map<String,Object> map=new HashMap<>();
       Credit credit=userService.selectCreditById(uid);
       List<Credit> credits=userService.AllCredit();
        map.put("credit",credit);
        map.put("credits",credits);
        return map;
    }
    @PostMapping(name="修改个人征信",value = "/updateUserCredit")
    @ResponseBody
    public String updateUserCredit(Integer uid, Integer cd_id){
        if(userService.updateUserCredit(uid, cd_id)){
            return "";
        }
        return "";
    }
}
